package com.dd.shop4j.website.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.dd.shop4j.console.order.service.OrderManagerService;
import com.dd.shop4j.website.controller.forms.OrderDetail;
import com.dd.shop4j.website.controller.forms.ShopcarItem;
import com.dd.shop4j.website.goods.service.OrderService;

@Controller
@RequestMapping("/flow")
public class FlowController {
	
	@Resource
	private OrderService orderService;
	
	@RequestMapping("checkout")
	public ModelAndView checkout(HttpSession session) {
		ModelAndView view = new ModelAndView("/website/checkout");
		view.addObject("items", session.getAttribute("SHOPCAR"));
		return view;
	}
	
	@RequestMapping("/importance")
	public String importance(OrderDetail orderDetail, HttpSession session) {
		List<ShopcarItem> items = (List<ShopcarItem>) session.getAttribute("SHOPCAR");
		ShopcarItem[] tmp=items.toArray(new ShopcarItem[items.size()]);
		orderDetail.setShopcarItem(tmp);
		orderService.insertGood(orderDetail);
		return "redirect:/";
	}
}
